package com.sunny.ynhz.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
//import com.nostra13.universalimageloader.core.ImageLoader;
import com.sunny.ynhz.R;
import com.sunny.ynhz.bean.WaterInformBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/12/012.
 */

public class WaterQualityinformAdapter extends BaseAdapter {
    Context context;
    List<WaterInformBean> informBeanList;

    public WaterQualityinformAdapter(Context context, List<WaterInformBean> informBeanList) {
        this.context = context;
        this.informBeanList = informBeanList;
    }

    @Override
    public int getCount() {
        return informBeanList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View contentView;
        WaterMsgHolder waterMsgHolder;
        if (view == null) {
            contentView = LayoutInflater.from(context).inflate(R.layout.item_water, null);
            waterMsgHolder = new WaterMsgHolder(contentView);
            contentView.setTag(waterMsgHolder);
        } else {
            contentView = view;
            waterMsgHolder = (WaterMsgHolder) contentView.getTag();
        }
        WaterInformBean waterInformBean = informBeanList.get(i);

        Glide.with(context).load(R.mipmap.ic_river).into(waterMsgHolder.img_msg);
        waterMsgHolder.tv_river_area.setText(waterInformBean.getArea());
        waterMsgHolder.tv_water_range.setText(waterInformBean.getRangWater());
        waterMsgHolder.tv_river_range.setText(waterInformBean.getRangRiver());
        waterMsgHolder.tv_river_name.setText(waterInformBean.getRiverName());
        int range = waterInformBean.getRange();
        switch (range) {
            case 1:
                waterMsgHolder.tv_range_flag.setText("I");
                waterMsgHolder.tv_range_flag.setBackgroundResource(R.drawable.ic_bg_1);
                break;
            case 2:
                waterMsgHolder.tv_range_flag.setText("II");
                waterMsgHolder.tv_range_flag.setBackgroundResource(R.drawable.ic_bg_2);
                break;
            case 3:
                waterMsgHolder.tv_range_flag.setText("III");
                waterMsgHolder.tv_range_flag.setBackgroundResource(R.drawable.ic_bg_3);
                break;
            case 4:
                waterMsgHolder.tv_range_flag.setText("IV");
                waterMsgHolder.tv_range_flag.setBackgroundResource(R.drawable.ic_bg_4);
                break;
            case 5:
                waterMsgHolder.tv_range_flag.setText("V");
                waterMsgHolder.tv_range_flag.setBackgroundResource(R.drawable.ic_bg_v);
                break;
            case 6:
                waterMsgHolder.tv_range_flag.setText("劣v");
                waterMsgHolder.tv_range_flag.setBackgroundResource(R.drawable.ic_bg_iv);
                break;
        }

        return contentView;
    }

    class WaterMsgHolder {
        @BindView(R.id.tv_river_area)
        TextView tv_river_area;
        @BindView(R.id.tv_river_range)
        TextView tv_river_range;
        @BindView(R.id.tv_water_range)
        TextView tv_water_range;
        @BindView(R.id.img_msg)
        ImageView img_msg;
        @BindView(R.id.tv_river_name)
        TextView tv_river_name;
        @BindView(R.id.tv_range_flag)
        TextView tv_range_flag;

        public WaterMsgHolder(View view) {
            ButterKnife.bind(this, view);
        }

    }
}
